<template>
	<view class="detail">
		<view class="title">
			{{result.title}}
		</view>
		<view class="info">
			<view class="editor">
				编辑：{{result.author}}
			</view>
			<view class="date">
				发布日期：{{result.posttime}}
			</view>
		</view>
		<view class="article">
			<rich-text :nodes="result.content"></rich-text>
		</view>
		<view class="disclaimer">
			免责声明免责声明
			免责声明免责声明
			免责声明免责声明
		</view>
	</view>
</template>

<script>
	import {
		parseTime
	} from '@/utils/time.js'
	export default {
		data() {
			return {
				// author: '',
				// title: '',
				// content: '',
				// posttime: null,
				result: {},

			};
		},
		onLoad(e) {
			
			this.getDetail(e.cid, e.id)
		},
		methods: {
			getDetail(cid, id) {
				let that = this;
				uni.request({
					url: 'https://ku.qingnian8.com/dataApi/news/detail.php',
					data: {
						cid: cid,
						id: id
					},
					success(res) {
						//此处写成普通函数形式，this指向此函数即success本身，
						//如果写成箭头函数形式，this指向上一层，即组件实例；

						// console.log(this)
						res.data.content = res.data.content.replace(/<img/gi,
						'<img style="max-width:100%"'); //兼容微信小程序，设置富文本中的图片最大宽度
						res.data.posttime=parseTime(res.data.posttime)
						that.result = res.data;
						//设置详情页导航栏标题 与当前新闻标题一致
						uni.setNavigationBarTitle({
							title:res.data.title
						})
					}
				})
			}
		}

	}
</script>

<style lang="less" scoped>
	.detail {
		padding: 20rpx;

		.title {
			width: 100%;
			font-weight: bold;
			font-size: 50rpx;
		}

		.info {
			background-color: #DEE1E6;
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 100%;
			font-size: 25rpx;
			margin: 30rpx auto;
			padding: 20rpx;
		}

		.article {

			// /deep/ img{
			// 	// 组件穿透写法，微信小程序不支持
			// 	max-width: 100%;
			// }
		}


		.disclaimer {
			background-color: #DEE1E6;
			color: grey;
			font-size: 25rpx;
			width: 100%;
			padding: 20rpx;
			margin: 20rpx auto;
		}
	}
</style>
